#ifndef FIELD_JS
#define FIELD_JS

#include "Concept.js"
#include "Patterns.js"

/* class */ Field = function(/* Concept */ concept)
{
	if (!(concept instanceof Concept))
	{
		throw "ArgumentException";
	}
	
	if (concept.Body != null)
	{
		console.log("FieldBody");
		throw "BadConceptException";
	}
	
	var _isStatic;
	var _name;
	
	(function()
	{
		var captures = Field.RegExp.exec(concept.Head);
		
		if (captures == null)
		{
			console.log("Field");
			throw "BadConceptException";
		}
		
		_isStatic = (captures[Field.StaticPosition] != undefined);
		_name = captures[Field.NamePosition];
	})();
	
	this.__defineGetter__("IsStatic", function() { return _isStatic; });
	this.__defineSetter__("IsStatic", function() { throw "MethodAccessibilityException"; });
	
	this.__defineGetter__("Name", function() { return _name; });
	this.__defineSetter__("Name", function() { throw "MethodAccessibilityException"; });
	
	this.ToJs = function()
	{
		return "var " + _name + ";";
	};
};

/* static bool */ Field.IsMatching = function(/* Concept */ concept)
{
	if (!(concept instanceof Concept))
	{
		throw "ArgumentException";
	}
	
	return concept.Body == null && Field.RegExp.test(concept.Head);
};

(function()
{
	var _pattern = "^private[ ](static[ ])?var " + Patterns.Identifier + "$";
	
	var _regExp = new RegExp(_pattern);
	Field.__defineGetter__("RegExp", function() { return _regExp; });
	Field.__defineSetter__("RegExp", function() { throw "MethodAccessibilityException"; });
	
	var _staticPosition = 1;
	Field.__defineGetter__("StaticPosition", function() { return _staticPosition; });
	Field.__defineSetter__("StaticPosition", function() { throw "MethodAccessibilityException"; });
	
	var _namePosition = 2;
	Field.__defineGetter__("NamePosition", function() { return _namePosition; });
	Field.__defineSetter__("NamePosition", function() { throw "MethodAccessibilityException"; });
})();

#endif
